package kr.pe.johnkim.pushchat.mobile.dao;

import kr.pe.johnkim.pushchat.mobile.domain.PushChatMessage;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 6. 12.
 */
@Repository
public class PushChatMessageDaoImpl extends SqlSessionDaoSupport implements PushChatMessageDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PushChatMessageDaoImpl.class);

    /**
     * 채팅방에 메시지를 추가 한다.
     *
     * @param pushChatMessage
     */
    @Override
    public void registerMessage(PushChatMessage pushChatMessage) {
        logger.info("registerMessage");
        this.getSqlSession().insert("PUSHCHAT_MESSAGE.registerMessage", pushChatMessage);
    }

    /**
     * 채팅 메시지 목록을 가져 온다.
     *
     * @param pushChatMessage
     * @return
     */
    @Override
    public List<PushChatMessage> selectMessageList(PushChatMessage pushChatMessage) {
        logger.info("selectMessageList");
        return this.getSqlSession().selectList("PUSHCHAT_MESSAGE.selectMessageList", pushChatMessage);
    }

    /**
     * 채팅방의 메시지를 비활성화 한다.
     *
     * @param pushChatMessage
     */
    @Override
    public void updateDeactivateMessage(PushChatMessage pushChatMessage) {
        logger.info("updateDeactivateMessage");
        this.getSqlSession().update("PUSHCHAT_MESSAGE.updateDeactivateMessage", pushChatMessage);
    }
}
